<!-- 投票展示卡 -->
<template>
  <el-card class="vote-card">
    <div
      class="header"
      slot="header"
    >
      <span>{{ title }}</span>
      <el-button
        v-show="!operation"
        style="float: right; padding: 3px 0"
        type="text"
        @click="toVote"
      >进入投票</el-button>
      <el-button
        v-show="operation"
        style="float: right; padding: 3px 0"
        type="text"
        @click="showVoteResult"
      >查看投票结果</el-button>
    </div>
    <div class="body">
      <img
        :src="image"
        class="image"
      />
      <div class="description">
        {{ description }}
      </div>
      <div class="duration">
        持续时间: {{ duration }}
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  props: {
    id: Number,
    title: String,
    image: String,
    description: String,
    duration: String,
    operation: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    toVote() {
      this.$router.replace({
        path: "/vote",
        query: {
          id: this.id,
        },
      });
    },
    showVoteResult() {
      this.$emit('showVoteResult', this.id)
    }
  },
};
</script>

<style scoped>
.vote-card {
  width: 400px;
  margin: 20px 15px;
  color: #5f5f5f;
}

.description {
  height: 32px;
  text-indent: 2em;
  font-size: 14px;

  /* 超出两行显示省略号 */
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  overflow: hidden;
  /*! autoprefixer: off */
  -webkit-box-orient: vertical;
}

.header {
  height: 20px;
  font-weight: 700;
}

.body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.duration {
  width: 100%;
  margin-top: 10px;
  font-size: 10px;
  display: flex;
  justify-content: flex-end;
}
</style>